package com.zis.auction.service.impl;

import com.alibaba.fastjson.JSON;
import com.zis.auction.dao.SubFileDao;
import com.zis.auction.model.Essay;
import com.zis.auction.model.SubFile;
import com.zis.auction.service.ISubFileInter;
import com.zis.base.impl.BaseInterImpl;
import com.zis.core.Constant;
import com.zis.core.ResponseEntity;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Create by wangshen 2018/1/14
 */
@Service
@Transactional("txManager")
public class SubFileInterImpl extends BaseInterImpl<SubFile> implements ISubFileInter {

    @Autowired
    private SQLManager sqlManager;

    @Autowired
    private SubFileDao subFileDao;

    @Override
    public String insert(SubFile subFile) throws Exception {
        int num = sqlManager.insert(subFile);
        if (num > 0) {
            return JSON.toJSONString(subFile);
        }
        return "error";
    }

    @Override
    public String update(SubFile subFile) throws Exception {
        return null;
    }

    @Override
    public String delete(String id) throws Exception {
        int num = sqlManager.deleteById(SubFile.class, id);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public SubFile selectById(String id) throws Exception {
        return null;
    }

    @Override
    public List<SubFile> findByCondition(SubFile subFile) throws Exception {
        return sqlManager.template(subFile);
    }

    @Override
    public List<SubFile> findByBussId(String bussId) throws Exception {
        return subFileDao.query(bussId);
    }
}
